package com.gc.ykqx.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gc.ykqx.R;
import com.gc.ykqx.service.entity.GridItem;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wsd on 2017/5/12.
 */

public class BaseGridViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<GridItem> gridItems;
    private LayoutInflater inflater;

    public BaseGridViewAdapter(Context mContext, List<GridItem> gridItems) {
        this.mContext = mContext;
        this.gridItems = gridItems;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return gridItems.size();
    }

    @Override
    public Object getItem(int position) {
        return gridItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        GridItem gridItem = gridItems.get(position);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.grid_menu_item, null, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (gridItem != null) {
            holder.itemName.setText(gridItem.getName());
            if (gridItem.isChecked()) {
                holder.itemName.setTextColor(Color.WHITE);
            } else {
               /* if (gridItem.getName().equals(Constant.YK)) {
                    holder.itemName.setTextColor(Color.RED);
                } else {*/
                holder.itemName.setTextColor(Color.parseColor("#707070"));
               /* }*/
            }
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.item_name)
        TextView itemName;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    interface OnTextTabClickListener {
        void onClickListener(int position);
    }
}
